package com.tc.juc.design;

import java.util.concurrent.locks.LockSupport;

/**
 * @Auther: tianchao
 * @Date: 2021/10/4 19:56
 * @Description:
 */
public class TestJiaoTiPark {
    static Thread t1;
    static Thread t2;
    static Thread t3;
    public static void main(String[] args) {
        JiaotiPark jiaotiPark = new JiaotiPark(10);
        t1 = new Thread(()->{jiaotiPark.print("a", t2);});
        t2 = new Thread(()->{jiaotiPark.print("b", t3);});
        t3 = new Thread(()->{jiaotiPark.print("c", t1);});
        t1.start();
        t2.start();
        t3.start();
        LockSupport.unpark(t1);
    }
}


class JiaotiPark{
    int loopNum;

    public JiaotiPark(int loopNum) {
        this.loopNum = loopNum;
    }

    public void print(String str,Thread next){
        for (int i = 0; i < loopNum; i++) {
            LockSupport.park();
            System.out.print(str);
            LockSupport.unpark(next);
        }
    }

}
